package org.footballmanager.pandafootball.common.intercepter;

import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.system.domain.FootDj;
import org.footballmanager.pandafootball.system.domain.FootGj;
import org.footballmanager.pandafootball.system.domain.FootWz;
import org.footballmanager.pandafootball.system.domain.FootYqts;
import org.footballmanager.pandafootball.system.service.FootDjService;
import org.footballmanager.pandafootball.system.service.FootGjService;
import org.footballmanager.pandafootball.system.service.FootWzService;
import org.footballmanager.pandafootball.system.service.FootYqtsService;
import org.footballmanager.pandafootball.system.service.impl.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

@Slf4j
@Component
public class MyStartupRunner implements CommandLineRunner {
	@Autowired
	private FootYqtsService footYqtsService;

	@Autowired
	private FootDjService footDjService;

	@Autowired
	private FootWzService footWzService;

	@Autowired
	private FootGjService footGjService;

	@Autowired
	private RedisService redisService;

	@Value("${title}")
	private String title;

	public void init() {
		List<FootDj> listdj = footDjService.getall();
		redisService.set("listdj", listdj);
		List<FootWz> listwz = footWzService.getall();
		redisService.set("listwz", listwz);
		List<FootGj> listgj = footGjService.getall();
		redisService.set("listgj", listgj);
		List<FootYqts> listyqts = footYqtsService.getall();
        redisService.set("listyqts", listyqts);
		if(!StringUtils.isEmpty(title)){
            redisService.set("title", title);
        }
	}

    @Override
    public void run(String... args) throws Exception {
        log.info(">>>>>>>>>>>>>>>服务启动执行，执行加载数据等操作<<<<<<<<<<<<<");
        init();
    }
}
